package com.lgy.ms.core.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author Gylin
 */
public class StreamUtil {

    private static String requestEncoding = "UTF-8";

    public static String readInputStream(InputStream inputStream) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, requestEncoding));
        StringBuilder sb = new StringBuilder();
        char[] buffer = new char[200];
        int len;
        while (-1 != (len = reader.read(buffer))) {
            sb.append(buffer, 0, len);
        }
        reader.close();
        return sb.toString();
    }

    public static String readInputStream(InputStreamReader inputStreamReader) throws IOException {
        BufferedReader reader = new BufferedReader(inputStreamReader);
        StringBuilder sb = new StringBuilder();
        char[] buffer = new char[200];
        int len;
        while (-1 != (len = reader.read(buffer))) {
            sb.append(buffer, 0, len);
        }
        reader.close();
        return sb.toString();
    }
}
